<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>角色列表</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="plugins/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="//at.alicdn.com/t/font_tnyc012u2rlwstt9.css" media="all" />
</head>
<body class="childrenBody">
	<blockquote class="layui-elem-quote news_search">
     <div class="layui-inline">
           <a class="layui-btn layui-btn-normal rolesAdd_btn">添加角色</a>
        </div>
	</blockquote>
	<div class="layui-form news_list">
	  	<table class="layui-table" id="roleList" lay-filter="roles"></table>
	</div>
	<div id="page"></div>
	<script type="text/javascript" src="js/jquery-1.11.2.min.js"></script>
	<script type="text/javascript" src="plugins/layui/layui.js"></script>
	<script type="text/javascript" src="/js/jquery.ztree.core.js"></script>
	<script type="text/javascript" src="/js/jquery.ztree.excheck.js"></script>
	
	<script type="text/html" id="barDemo">
		<a class="layui-btn layui-btn-xs" lay-event="giveAuth"><i class="iconfont icon-edit"></i>分配权限</a>
	    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon"></i>删除</a>
	</script>
	<script type="text/javascript">

	layui.use(['table','form'], function(){
	    var table = layui.table;
	    //方法级渲染
	    var tableIns=table.render({
	        elem: '#roleList'
	        ,url: '/roles'
	        ,cols: [[
	            {field:'id', title: 'ID', width:'10%'}
	            ,{field:'roledesc', title: '角色名称'}
	            ,{title: '操作',align:'center', toolbar: '#barDemo'}

	        ]]
	        ,id: 'testReload'
	        ,page: true
	    });

	    table.on('tool(roles)', function(obj){
	    	  var layEvent = obj.event;
           	 var ids=obj.data.id;
	    	  if(layEvent === 'del'){ //删除
	    	    layer.confirm('真的删除该角色吗', function(index){
	    	        layer.close(index);
	    	      $.ajax({  
	    	            type: "POST",  
	    	            url:"/roles/delete",  
	    	            data:{id:ids},// 序列化表单值  
	    	            success: function(res) {
	    	            	if(res.code==2000){
	    	            		top.layer.close(index);
	    	          			top.layer.msg("删除成功");
	    	          			obj.del();
	    	            	}
	    	            } ,
	    		 		 error: function(res) {
	    		             layer.msg("请求服务");
	    		         } 
	    	        }); 
	    	    });
	    	  } else if(layEvent === 'giveAuth'){
	    		  allotResources(ids);
	    	  }
	    	});
	});
	
	$(window).one("resize",function(){
		$(".rolesAdd_btn").click(function(){
			var index = layui.layer.open({
				title : "添加角色",
				type : 2,
				content : "role/rolesAdd.html",
				success : function(layero, index){
					
				}
			})			
			layui.layer.full(index);
		})
	}).resize();
	
	  function allotResources(id){
	        var index = layui.layer.open({
	            title: "分配权限",
	            type: 2,
	            content: "role/allotResources.html?id="+id,
	            success: function (layero, index) {

	            }
	        });
	        //改变窗口大小时，重置弹窗的高度，防止超出可视区域（如F12调出debug的操作）
	        $(window).resize(function () {
	            layui.layer.full(index);
	        });
	        layui.layer.full(index);
	  }

	
	</script> 
</body>
</html>